package com.yungu.swift.order.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.order.dao.OrderRechargeMapper;
import com.yungu.swift.order.model.dto.OrderRechargeDto;
import com.yungu.swift.order.model.param.AdminRechargeBillPageParam;
import com.yungu.swift.order.model.vo.AdminRechargeBillVo;
import com.yungu.swift.order.service.OrderRechargeService;
import com.yungu.swift.utils.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service
public class OrderRechargeServiceImpl extends BaseServiceImpl<OrderRechargeDto> implements OrderRechargeService {

    @Autowired
    private OrderRechargeMapper orderRechargeMapper;

    @Override
    protected IMapper<OrderRechargeDto> getMapper() {
        return orderRechargeMapper;
    }

    @Override
    public ResponseData<PageVo<AdminRechargeBillVo>> rechargeBillPage(AdminRechargeBillPageParam billPageParam) {
        PageBounds pageBounds = new PageBounds(billPageParam.getPageNum(), billPageParam.getPageSize());
        if (StringUtils.isNotEmpty(billPageParam.getSortString())) {
            pageBounds.setOrders(Order.formString(billPageParam.getSortString()));
        }
        PageList<AdminRechargeBillVo> pageList = orderRechargeMapper.rechargeBillPage(billPageParam, pageBounds);
        PageVo<AdminRechargeBillVo> pageVo = new PageVo(billPageParam.getPageNum(), billPageParam.getPageSize(),
                pageList.getPaginator().getTotalCount());
        pageVo.setItems(pageList);
        return ResponseData.buildSuccessResponse(pageVo);
    }

    @Override
    public ResponseData<List<AdminRechargeBillVo>> rechargeBillExport(AdminRechargeBillPageParam billPageParam) {
        return ResponseData.buildSuccessResponse(orderRechargeMapper.rechargeBillPage(billPageParam));
    }

    @Override
    public ResponseData<Map<String, Object>> rechargeBillCount(AdminRechargeBillPageParam billPageParam) {
        return ResponseData.buildSuccessResponse(orderRechargeMapper.rechargeBillCount(MapUtils.convertObjToMap(billPageParam)));
    }
}
